package com.kornero.auto.entities;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.net.URI;
import java.util.Date;

public class Car implements Serializable, Comparable<Car> {
    private static final long serialVersionUID = 3687601554098923890L;

    private static final transient Logger logger = LoggerFactory.getLogger(Car.class);

    private final URI link;
    private final String model;
    private final String price;
    private final String year;
    private final String engineKPP;
    private final String type;
    private final String distance;
    private final String photo;
    private final String carcase;
    private final String color;
    private final String city;
    private final String customs;
    private final String existence;
    private final Date date;

    private boolean checked = false;

    public Car(String link,
               String model,
               String price,
               String year,
               String engineKPP,
               String type,
               String distance,
               String photo,
               String carcase,
               String color,
               String city,
               String customs,
               String existence,
               boolean checked,
               Date date) {
        this.link = URI.create(link.trim().toLowerCase());
        this.model = model;
        this.price = price;
        this.year = year;
        this.engineKPP = engineKPP;
        this.type = type;
        this.distance = distance;
        this.photo = photo;
        this.carcase = carcase;
        this.color = color;
        this.city = city;
        this.customs = customs;
        this.existence = existence;
        this.setChecked(checked);
        this.date = date;
    }

    public URI getLink() {
        return link;
    }

    public String getModel() {
        return model;
    }

    public String getPrice() {
        return price;
    }

    public String getYear() {
        return year;
    }

    public String getEngineKPP() {
        return engineKPP;
    }

    public String getType() {
        return type;
    }

    public String getDistance() {
        return distance;
    }

    public String getPhoto() {
        return photo;
    }

    public String getCarcase() {
        return carcase;
    }

    public String getColor() {
        return color;
    }

    public String getCity() {
        return city;
    }

    public String getCustoms() {
        return customs;
    }

    public String getExistence() {
        return existence;
    }

    public boolean isChecked() {
        return checked;
    }

    public Date getDate() {
        return date;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    @Override
    public String toString() {
        final StringBuilder stringBuilder = new StringBuilder("Car :\n\t");
        stringBuilder.append("link=").append(link);
        stringBuilder.append(", model=").append(model);
        stringBuilder.append(", price=").append(model);
        stringBuilder.append(", year=").append(year);
        stringBuilder.append(", engineKPP=").append(engineKPP);
        stringBuilder.append(", type=").append(type);
        stringBuilder.append(", distance=").append(distance);
        stringBuilder.append(", photo=").append(photo);
        stringBuilder.append(", carcase=").append(carcase);
        stringBuilder.append(", color=").append(color);
        stringBuilder.append(", city=").append(city);
        stringBuilder.append(", customs=").append(customs);
        stringBuilder.append(", existence=").append(existence);
        stringBuilder.append(", isChecked=").append(isChecked());
        stringBuilder.append(", date=").append(date);
        return stringBuilder.toString();
    }

    @Override
    public boolean equals(final Object anObject) {
        if (this == anObject) {
            return true;
        } else if (anObject instanceof Car) {
            final Car that = (Car) anObject;
            return this.getLink().equals(that.getLink());
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.getLink().hashCode();
    }

    @Override
    public int compareTo(final Car that) {
        if (this.equals(that)) {
            return 0;
        }
        return this.getDate().compareTo(that.getDate());
    }
}